<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns="http://www.w3.org/1999/xhtml">
    
    <h:form id="requestForm" enctype="multipart/form-data">

        <p:outputPanel id="requestPanel">

            <p:dialog widgetVar="requestDialog" header="#{prop['dialogRequest.header']} #{currentRequestBean.current.id}"
                      closeOnEscape="true" >

                <p:tabView activeIndex="0" id="requestTabView">
                    <p:tab title="#{prop['dialogRequest.tabmain']}">
                        <h:panelGrid columns="2">

                            <h:outputText value="#{prop['common.organization']}"/>
                            <h:outputText value="#{currentRequestBean.current.createdBy.organization.toString()}"/>                    

                            <h:outputText value="#{prop['common.createdBy']}"/>
                            <h:outputText value="#{currentRequestBean.current.createdBy.toString()}"/>                    

                            <h:outputText value="#{prop['common.createdDate']}"/>                    
                            <h:outputText value="#{currentRequestBean.current.createdDate}">
                                <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                            </h:outputText>

                            <h:outputText value="#{prop['common.description']}"/>
                            <h:inputText value="#{currentRequestBean.current.description}" size="50"
                                         disabled="#{not currentRequestBean.enableChangeDescription}"/>

                            <h:outputText value="#{prop['common.text']}"/>
                            <h:outputText value="#{currentRequestBean.current.text}" escape="false"/>

                            <h:outputText value="#{prop['common.addText']}"/>
                            <h:inputTextarea value="#{currentRequestBean.addText}" rows="4" cols="50"
                                         disabled="#{not currentRequestBean.enableAddText}"/>


                            <h:outputText value="#{prop['common.serviceObject']}"/>
                            <h:selectOneMenu value="#{currentRequestBean.current.serviceObject}"
                                             disabled="#{not currentRequestBean.enableChangeServiceObject}">
                                <f:selectItems value="#{currentRequestBean.selectItemServiceObject}"/>
                            </h:selectOneMenu>



                            <h:outputText value="#{prop['common.priority']}"/>
                            <h:selectOneMenu value="#{currentRequestBean.current.priority}"
                                             disabled="#{not currentRequestBean.enableChangePriority}">
                                <f:selectItems value="#{prioritytBean.selectItemPriority}"/>
                            </h:selectOneMenu>


                            <h:outputText value="#{prop['common.stateRequest']}"/>
                            <h:selectOneMenu value="#{currentRequestBean.current.stateRequest}"
                                             disabled="#{not currentRequestBean.enableChangeStateRequest}">
                                <f:selectItems value="#{currentRequestBean.selectItemsAvailableStateRequest}"/>
                            </h:selectOneMenu>



                            <h:outputText value="#{prop['common.stateDate']}"/>
                            <h:outputText value="#{currentRequestBean.current.stateDate}">
                                <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                            </h:outputText>

                            <h:outputText value="#{prop['common.performer']}"/>
                            <h:selectOneMenu value="#{currentRequestBean.current.performer}"
                                             disabled="#{not currentRequestBean.enableChangePerfomer}">
                                <f:selectItems value="#{userHDBean.selectItemPerfomer}"/>
                            </h:selectOneMenu>

                        </h:panelGrid>
                        
                        <br/>
                        <br/>
                        
                        <p:fileUpload fileUploadListener="#{currentRequestBean.handleFileUpload}"
                                      mode="advanced" update="requestTabView:imageTab" 
                                      label="#{prop['dialogRequest.fileUploadlabel']}" 
                                      uploadLabel="#{prop['dialogRequest.fileUploaduploadLabel']}" 
                                      cancelLabel="#{prop['dialogRequest.fileUploadcancelLabel']}"
                                      multiple="true"
                                      sizeLimit="100000" disabled="#{not currentRequestBean.enableAddFile}"
                                      allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
                        
                        

                    </p:tab >
                        
                    
                    <p:tab title="#{prop['dialogRequest.tabfiles']}" 
                           rendered="#{not empty currentRequestBean.listFiles}" id="imageTab">
                        
                        <p:dataTable value="#{currentRequestBean.listFiles}" var="itemFile">
                        
                            <p:column headerText="#{prop['dialogRequest.uploadedDate']}">
                                <h:outputText value="#{itemFile.uploadedDate}">
                                    <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                                </h:outputText>
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.uploadedBy']}">
                                <h:outputText value="#{itemFile.uploadedBy.name}" />
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.itemFile']}">
                                <p:commandLink value="#{itemFile.name}" 
                                         oncomplete="imageDialog.show()"
                                         update=":imageForm:imagePanel">
                                    <f:setPropertyActionListener target="#{imageAsStreamContent.currentImage}" 
                                                                 value="#{itemFile}" />
                                </p:commandLink>
                            </p:column>
                        
                        </p:dataTable>
                        
                    </p:tab> 
                    
                    
                    
                    
                    <p:tab title="#{prop['dialogRequest.tabhistory']}" 
                           rendered="#{not empty currentRequestBean.listChanges}">
                        
                        <p:dataTable value="#{currentRequestBean.listChanges}" 
                                     var="itemChange">
                            
                            <p:column headerText="#{prop['dialogRequest.modifiedDate']}">
                                <h:outputText value="#{itemChange.modifiedDate}">
                                    <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                                </h:outputText>
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.modifiedBy']}">
                                <h:outputText value="#{itemChange.modifiedBy.name}" />
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.propertyName']}">
                                <h:outputText value="#{itemChange.propertyName}" />
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.propertyValue']}">
                                <h:outputText value="#{itemChange.propertyValue}" />
                            </p:column>
                            
                        </p:dataTable>
                        
                        
                    </p:tab>
                    
                    
                    
                    <p:tab title="#{prop['dialogRequest.tabhistoryrequest']}" 
                           rendered="#{not empty currentRequestBean.listRequestsByServiceObject}">
                        
                        <p:dataTable value="#{currentRequestBean.listRequestsByServiceObject}" 
                                     var="item">
                            
                            <p:column headerText="Id">
                                <h:outputText value="#{item.id}"/>
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.tabhistoryrequestcreatedDate']}">
                                <h:outputText value="#{item.createdDate}">
                                    <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                                </h:outputText>
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.tabhistoryrequestdescription']}">
                                <h:outputText value="#{item.description}"/>
                            </p:column>
                            
                            <p:column headerText="#{prop['dialogRequest.tabhistoryrequeststateRequest']}">
                                <h:outputText value="#{item.stateRequest.name}" />
                            </p:column>
                              
                            <p:column headerText="#{prop['dialogRequest.tabhistoryrequeststateDate']}">
                                <h:outputText value="#{item.stateDate}">
                                    <f:convertDateTime pattern="HH:mm dd.MM.yyyy"/>
                                </h:outputText>
                            </p:column>
                            
                        </p:dataTable>
                        
                        
                    </p:tab>
                    
                    
                    
                </p:tabView>
                <br/>
                <br/>

                <div style="text-align: center">
                    <p:commandButton actionListener="#{currentRequestBean.update()}" 
                                     action="#{currentRequestBean.getActionString()}"
                                 update=":form"
                                 value="#{prop['dialogRequest.commandButton']}"
                                 oncomplete="requestDialog.hide()"/>
                </div>
            </p:dialog>


        </p:outputPanel>
        
        
        
    </h:form>
    
    
    
    
    <h:form id="imageForm">

        <p:outputPanel id="imagePanel">

            <p:dialog widgetVar="imageDialog" header="#{imageAsStreamContent.currentImage.name}" 
                      closeOnEscape="true" height="600" width="800">
                
                <p:graphicImage value="#{imageAsStreamContent.currentImageAsStreamedContent}"/>
                
            </p:dialog>

        </p:outputPanel>
    </h:form>
    
</ui:composition>